package com.kb.controller.icQuote;


import com.kb.common.ApiResponse;
import com.kb.common.MeException;
import com.kb.domain.icQuote.OrderTo;
import com.kb.domain.icQuote.Product;
import com.kb.domain.icQuote.QueryTO;
import com.kb.service.QuoteService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/quote")
//云汉询价
public class QuoteController {


    @Resource
    private QuoteService quoteService;

    @GetMapping("/updateToken")
    @XxlJob("updateToken")
    @ResponseBody
    public ApiResponse updateToken()  {
        quoteService.updateToken();
        return ApiResponse.success("ok");
    }


    @PostMapping("/query")
    @ResponseBody
    public ApiResponse query(@RequestBody QueryTO to){

        List<Product> query = quoteService.query(to);
        if(query==null){
            return  ApiResponse.error("错误，未找到相关数据");
        }
        return ApiResponse.successCount(query,query.size());
    }


    @PostMapping("/order")
    @ResponseBody
    public ApiResponse order(@RequestBody OrderTo to){

        ApiResponse reuslt=quoteService.order(to);


        return reuslt;
    }




}
